package org.fhm.zdte.common.util;

import com.google.gson.Gson;
import org.fhm.substrate.annotation.Component;
import org.fhm.zdte.common.standard.IJsonConvertor;

/**
 * Common convertor that is convert between strings and objects.
 *
 * @author 谭波
 * @since 2024/2/2
 */
@Component
public class CommonJsonConvertor implements IJsonConvertor {

    private final Gson gson = new Gson();

    @Override
    public String toJson(Object obj) {
        return gson.toJson(obj);
    }

    @Override
    public <T> T fromJson(String jsonStr, Class<T> clazz) {
        return gson.fromJson(jsonStr, clazz);
    }

}
